import request from 'utils/request';

// 获取文章列表
export const getArticles = (params) => {
  return request({
    url: '/mp/articles',
    params,
  });
};

// 删除文章
export const deleteArticle = (id) => {
  return request({
    url: `/mp/articles/${id}`,
    method: 'delete',
  });
};

// 发表文章和存入草稿，根据draft,true为存入草稿，false为发表文章
export const publishArticle = ({ draft = false, ...data }) => {
  return request({
    url: `/mp/articles?draft=${draft}`,
    method: 'post',
    data,
  });
};

// 获取文章详情
export const getArticleDetail = (id) => {
  return request({
    url: `/mp/articles/${id}`,
  });
};

// 修改文章
export const editArticle = (data, draft) => {
  return request({
    url: `/mp/articles/${data.id}?draft=${draft}`,
    method: 'put',
    data,
  });
};
